package com.six.firstpage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.Notice;
import com.six.core.vo.Result;
import com.six.firstpage.service.NoticeService;
import com.six.firstpage.vo.NoticeVo;
import com.six.firstpage.vo.SearchTime;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.intellij.lang.annotations.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.text.rtf.RTFEditorKit;
import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-27 14:37
 * @Description:
 */
@Api(value = "firstpage/notice", tags = {"公告管理后台接口"})
@RestController
@RequestMapping("firstpage/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;


    @GetMapping("getAllNotice")
    public Result getAllNotice(){
        List<Notice> allNotice = noticeService.getAllNotice();
        return new Result(2000,"查询所有公告成功",allNotice);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "NoticeVo", name = "noticeVo", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "current", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/getNoticeByTime/{current}/{pageSize}")
    public IPage<NoticeVo> getNoticeByTime(@RequestBody NoticeVo noticeVo , @PathVariable  @RequestParam(defaultValue = "1") Integer current, @PathVariable @RequestParam(defaultValue = "5") Integer pageSize){

        IPage<NoticeVo> noticeByTime = noticeService.getNoticeByTime(noticeVo, current, pageSize);

        return noticeByTime;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Notice", name = "notice", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addNotice")
    public Integer addNotic(@RequestBody Notice notice){
       return noticeService.addNotice(notice);

    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Notice", name = "notice", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateNotice")
    public Integer updateNotic(@RequestBody Notice notice){
        return noticeService.updateNotice(notice);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delNotice/{id}")
    public Integer delNotice(@PathVariable Integer id){
        return noticeService.delNotice(id);
    }
}
